// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import axios from "axios";
import VueCookies from "vue-cookies";
import { QuillEditor } from "@vueup/vue-quill";
import "@vueup/vue-quill/dist/vue-quill.snow.css";
import global_variable from "./js/global_variable";
import "./css/common.css";
import { createPinia } from 'pinia'

const pinia = createPinia()
const app = createApp(App);

// 配置 axios
axios.defaults.withCredentials = true;
app.config.globalProperties.$axios = axios;

// 配置 cookies
app.use(VueCookies);
app.use(pinia)
// 配置全局变量
app.config.globalProperties.GLOBAL = global_variable;

// 配置 Element Plus
app.use(ElementPlus);

// 配置 Quill 编辑器
app.component("QuillEditor", QuillEditor);

// 配置路由
app.use(router);

// 配置 axios 拦截器
const AuthenticationFailCode = 3005;
axios.interceptors.response.use(
  (response) => {
    console.log(response);
    if (response.data.code == AuthenticationFailCode) {
      router.push({ name: "Login" });
    }
    return response;
  },
  (error) => {
    console.log(error);
    if (error.response) {
      // 处理错误响应
    }
    return Promise.reject(error.response.data);
  }
);

app.mount("#app");
